From fc9212c4045a9c2a7d713b58ae2a96bf2a59c6d5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Mar 2015 19:59:34 -0700 Subject: [PATCH] Fix `cargo run` with no binaries --- src/cargo/ops/cargo_run.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 787c1e374..5f5a36113 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -14,16 +14,23 @@ pub fn run(manifest_path: &Path, try!(src.update()); let root = try!(src.root_package()); - // Make sure that we're only running at most one binary. The `compile` step - // will verify that we're buliding at least one binary, so we don't check - // for that form of existence here. let mut bins = root.manifest().targets().iter().filter(|a| { !a.is_lib() && !a.is_custom_build() && match options.filter { CompileFilter::Everything => a.is_bin(), CompileFilter::Only { .. } => options.filter.matches(a), } }); - let _ = bins.next(); + if bins.next().is_none() { + match options.filter { + CompileFilter::Everything => { + return Err(human("a bin target must be available for \ + `cargo run`")) + } + CompileFilter::Only { .. } => { + // this will be verified in cargo_compile + } + } + } if bins.next().is_some() { match options.filter { CompileFilter::Everything => { -- 2.30.2